package jk.spider.core.task.work.impl;

import java.net.MalformedURLException;
import java.net.URL;

import jk.spider.core.SpiderController;
import jk.spider.core.event.impl.ResourceParsedOkEvent;
import jk.spider.core.task.work.InterpreteHTMLTask;
import jk.spider.model.Resource;
import jk.spider.util.SpiderUtil;

import org.apache.log4j.Logger;

public abstract class SrcInterpreteHTMLTask  extends InterpreteHTMLTask {
	protected static final Logger log = Logger.getLogger(SrcInterpreteHTMLTask.class);
	
	protected SpiderUtil util ;
	protected String endTime;

	public SrcInterpreteHTMLTask(SpiderController controller, Resource resource) {
		super(controller, resource);
		util = new SpiderUtil();
		endTime = controller.getContent().getEndCrawlDate();
	}
	
	public void execute() {
		String htmlSource = this.getHtmlSource();
		this.urlFound(htmlSource);
		notifyEvent(resource, new ResourceParsedOkEvent(controller, resource) );
	}
	
	protected String getHost(String url) {
		try {
			return new URL(url).getHost();
		} catch (MalformedURLException e) {
			e.printStackTrace();
		}
		return null;
	}
	
	public void prepare() {	}
	
	public abstract void urlFound(String htmlSrc);

}
